using System;
using System.Data;
using System.Configuration;
using System.Web;
using Xeml.Document;
using System.Drawing;
using System.Drawing.Drawing2D;

namespace Xeml.Visualization
{
    public class VisEvent : VisualTimeElement
    {
        private Event _event;

        public Event Event
        {
            get { return _event; }
           
        }

        public override TimeSpan Time
        {
            get
            {
                return _event.TimePoint;
            }
            set
            {
                _event.TimePoint = value;
            }
        }

        public VisEvent(Event ev, float x, float y, SizeF size)
        {
            _event = ev;
            this.x = x;
            this.y = y;
            this.Size = new SizeF(16f, 20f);//size;
            this._event.TimePointHasChanged += new EventHandler<Mpi.Common.PropertyHasChangedEventArgs<TimeSpan>>(_event_TimePointHasChanged);
           // this.observationPoint.TimePointHasChanged += new EventHandler<Mpi.Common.PropertyHasChangedEventArgs<TimeSpan>>(observationPoint_TimePointChanged);       
        }

        void _event_TimePointHasChanged(object sender, Mpi.Common.PropertyHasChangedEventArgs<TimeSpan> e)
        {
            OnXLocationUpdateNeeded(e);
        }

        protected override void SetShape()
        {
            RectangleF bounds = new RectangleF();
            bounds.Size = this.size;
            bounds.X = this.x;
            bounds.Y = this.y - this.size.Height;

            this.shape = CreateBlizzard(bounds);
            //this.shape.AddRectangle(bounds);
        }

        private GraphicsPath CreateBlizzard(RectangleF rct)
        {
            GraphicsPath ret = new GraphicsPath();
            ret.StartFigure();

            PointF p1 = new PointF() ;
            PointF p2 = new PointF(); ;
            p1.X = rct.X + (rct.Width / 3f);
            p1.Y = rct.Y + (rct.Height / 9f);
            p2.X = rct.X + (0);
            p2.Y = rct.Y + (rct.Height / 2f);
            ret.AddLine(p1, p2);

            
            p1 = new PointF(p2.X, p2.Y);
            p2 = new PointF();
            p2.X = rct.X + (rct.Width / 3f);
            p2.Y = rct.Y + (rct.Height / 2f - (rct.Height / 10f));
            ret.AddLine(p1, p2);

            p1 = new PointF(p2.X, p2.Y);
            p2 = new PointF();
            p2.X = rct.X + (0f);
            p2.Y = rct.Y + (rct.Height);
            ret.AddLine(p1, p2);

            p1 = new PointF(p2.X, p2.Y);
            p2 = new PointF();
            p2.X = rct.X + (2 * (rct.Width/3f));
            p2.Y = rct.Y + (3 * (rct.Height/8f));
            ret.AddLine(p1, p2);

            p1 = new PointF(p2.X, p2.Y);
            p2 = new PointF();
            p2.X =  rct.X + ((rct.Width / 2f));
            p2.Y = rct.Y + (3 * (rct.Height / 8f));
            ret.AddLine(p1, p2);

            p1 = new PointF(p2.X, p2.Y);
            p2 = new PointF();
            p2.X = rct.X + ((rct.Width));
            p2.Y = rct.Y + (0);
            ret.AddLine(p1, p2);

            p1 = new PointF(p2.X, p2.Y);
            p2 = new PointF();
            p2.X = rct.X + (rct.Width / 3f);
            p2.Y = rct.Y + (rct.Height / 9f);
            ret.AddLine(p1, p2);

            ret.CloseFigure();
            return ret;


        }
    }
}
